package com.zhanghao.sdk.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.zhanghao.sdk.view.ZHFloatView;

public class ZHUiUtils {

    /**
     * 隐藏状态栏
     * @param context activity上下文
     * 使用说明：
     * 需要在setContentView之前调用才能生效
     */
    public static void hideStatusBar(Context context){
        try {
            ((Activity)context).requestWindowFeature(Window.FEATURE_NO_TITLE);
            ((Activity)context).getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }catch (Exception e){
            ZHLog.e(e.getMessage());
        }
    }

    /**
     * 添加布局
     * @param context 容器上下文
     * @return 父布局
     */
    public static ZHFloatView addZHView(Context context, View view, IAddZHViewCallback attributeConfig){
        try {
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
            layoutParams = attributeConfig.addViewBefore(layoutParams);
            ZHFloatView zhView = new ZHFloatView(layoutParams);
            zhView.setItem(view);
            ((Activity)context).addContentView(zhView.getItem(),zhView.getLayoutParams());
            zhView.setParentView((ViewGroup)zhView.getItem().getParent());
            return zhView;
        } catch (Exception e){
            ZHLog.e(e.getMessage());
        }
        return null;
    }
}
